<%@page import="com.bionic.banking.core.enums.*"%>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<%@taglib uri="../WEB-INF/taglib.tld" prefix="m" %> 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Register a new bank account</title>                                      
        <script type="text/javascript" src="../resources/script/ui/jquery-ui.js"></script>        
        <script type="text/javascript">
            $(document).ready(function() 
            {                
                $("[required=true]").after("<span></span>");
                $("#btnSubmit").click(function(){
                    var error=false;
                    $("span").text("");//Clear all error message
                                
                    $("[class~=Red]").removeClass("Red");
                    if(trim($("#accounttype").val())==""){
                        $("#accounttype").next().text(" Please enter the account type");
                        $("#accounttype").addClass("Red");
                        error=true;
                    } 
                    if(trim($("#customerid").val())==""){
                        $("#customerid").next().text(" Please choose a customer");
                        $("#customerid").addClass("Red");
                        error=true;
                    } 
                    if(trim($("#balance").val())==""){
                        $("#balance").next().text(" Please set begin balance");
                        $("#balance").addClass("Red");
                        error=true;
                    } 
                    $("[class=Red]").eq(0).focus();
                    return !error;
                });
            });
            
            function trim(x) {
                return x.replace(/^\s+|$\s+/,'');
            }                 
        </script>            
    </head>
    <body>
        <h3>Create a new bank account</h3>       
        <form id="newAccountForm" action="Controller" method="POST">
            <input type="hidden" name="command" value ="createBankAccount"/>           
            <jsp:useBean id="domainHelperBean" scope="page"
                         class="com.bionic.banking.logic.DomainUtil" />
            <jsp:useBean id="customerBean" scope="page"
                         class="com.bionic.banking.logic.controller.CustomerController" />
            <div id="divBankaccount" >
                <table id="tblBankAccount" border="1">  
                    <tr>
                      <td>Customer</td>
                      <td>
                          <input id="customerId" name="customerId" value="${myCustomerId}" hidden="true" />
                          <a 
                             href="javascript:viewCustomerRecord(${customerId});">
                              ${customerBean.getDetails(myCustomerId)}</a>                          
                      </td>
                      <td>Description</td>
                        <td colspan="3" style="height: 200;" >
                            <input style="height: 200;width: 500" id = "description" name="description" />
                        </td>   
                    </tr>      
                    <tr><td>Account Type</td>
                        <td>
                            <select name="accountType" id="accountType">                                                                  <c:forEach var="item"  items="${domainHelperBean.getAccountTypes()}">
                                    <option value="${item}">${item.toString()}</option>                                                   </c:forEach>
                            </select>
                        </td>
                        <td> in </td>
                        <td>                                            
                            <select name="currency" id="currency" >
                                <c:forEach var="item" items="${domainHelperBean.getCurrencies()}">
                                    <option value="${item.getCode()}">
                                        ${item}
                                    </option>
                                </c:forEach>
                            </select>                                            
                        </td>
                    </tr>
                    <tr>
                        <td>Begin balance</td>
                        <td>
                            <input id = "balance" name="balance" required="true"
                                   <m:maskedInput mask="^[0-9]{0,7}[.]?[0-9]{0,3}$"/> />
                        </td>
                        <td>Credit line</td>
                        <td><input id = "creditline" name="creditLine" value="0"
                                   <m:maskedInput mask="^[0-9]{0,10}[.]?[0-9]{0,10}$"/> /></td>
                    </tr>
                </table>

                <br/>
                <input type="submit" id="btnSubmit" value="Save" />         
                <a href="Controller?command=viewBankAccountsList"><strong>Go to list</strong></a>
            </div>
        </form>      
    </body>
</html>
